import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'index',
      component: () => import('@/views/homeIndex.vue'),
    },
    {
      path: '/about',
      name: 'about',
      component: () => import('@/views/aboutIndex.vue'),
    }

  ],
})

router.beforeEach((to, from, next) => {
  window.dispatchEvent(new CustomEvent('start-loading'));
  setTimeout(() => {
    try {
      next();
    } catch (error) {
      console.log(error);
      next(false);
    } finally {
      window.dispatchEvent(new CustomEvent('end-loading'));
    }
  }, 100);
});



export default router
